package gdr.dev.creator;

import java.awt.Color;
import java.awt.image.BufferedImage;

import com.golden.gamedev.object.AnimatedSprite;
import com.golden.gamedev.object.Timer;

import gdr.action.Classe;
import gdr.action.descriptor.ActionMenu;
import gdr.action.descriptor.Azione;
import gdr.action.descriptor.Magic;
import gdr.action.descriptor.Summon;
import gdr.dev.SuperGDR9000;
import gdr.player.DefaultPlayer;
import gdr.player.DefaultSummonedPlayer;

public class ClassCreator {

	public static Classe createClasseSummoner(SuperGDR9000 gdr, DefaultPlayer summoner){
		Classe c = new Classe();
		c.setName("Summoner");
		c.setSprite(createSprite(gdr, 4*40));
		Azione a = ActionCreator.createMove();
		c.getAzioni().add(a);
		
		a = ActionCreator.createAttack();
		c.getAzioni().add(a);
		
		ActionMenu m = ActionCreator.createActionMenu("Summon");
		c.getAzioni().add(m);
		
		DefaultSummonedPlayer s = (DefaultSummonedPlayer)PlayerCreator.createTank(gdr, "Summon1", 10, summoner);
		Summon summon = ActionCreator.createSummon(s, 10, 1, 1);
		m.getAzioni().add(summon);
		
		s = (DefaultSummonedPlayer)PlayerCreator.createWizard(gdr, "Summon2", 20, summoner);
		summon = ActionCreator.createSummon(s, 20, 4, 2);
		m.getAzioni().add(summon);
		
		s = (DefaultSummonedPlayer)PlayerCreator.createWizard(gdr, "Summon3", 50, summoner);
		summon = ActionCreator.createSummon(s, 50, 7, 3);
		m.getAzioni().add(summon);
	
		return c;
	}
	
	public static Classe createClasseTank(SuperGDR9000 gdr){
		Classe c = new Classe();
		c.setName("Tank");
		c.setSprite(createSprite(gdr, 4*60));
		
		
		Azione a = ActionCreator.createMove();
		c.getAzioni().add(a);
		
		a = ActionCreator.createAttack();
		c.getAzioni().add(a);
		return c;
	}

	public static Classe createClasseWizard(SuperGDR9000 gdr){
		Classe c = new Classe();
		c.setName("Wizard");
		c.setSprite(createSprite(gdr, 4*80));
		
		Azione a = ActionCreator.createMove();
		c.getAzioni().add(a);
		
		a = ActionCreator.createAttack();
		c.getAzioni().add(a);
		
		ActionMenu m = ActionCreator.createActionMenu("Magic");
		c.getAzioni().add(m);
		
		m.getAzioni().add(ActionCreator.createMagic("Fire 1", Magic.LivelloMagia.BASE, Color.red, 0, 80));
		m.getAzioni().add(ActionCreator.createMagic("Fire 2", Magic.LivelloMagia.INTERMEDIO, Color.red, 3, 100));
		m.getAzioni().add(ActionCreator.createMagic("Fire 3", Magic.LivelloMagia.AVANZATO, Color.red, 10, 120));
		
		m.getAzioni().add(ActionCreator.createMagic("Ice 1", Magic.LivelloMagia.BASE, Color.cyan, 0, 80));
		m.getAzioni().add(ActionCreator.createMagic("Ice 2", Magic.LivelloMagia.INTERMEDIO, Color.cyan, 2, 100));
		m.getAzioni().add(ActionCreator.createMagic("Ice 3", Magic.LivelloMagia.AVANZATO, Color.cyan, 10, 120));
		
		m.getAzioni().add(ActionCreator.createMagic("Wind 1", Magic.LivelloMagia.BASE, Color.green, 0, 80));
		m.getAzioni().add(ActionCreator.createMagic("Wind 2", Magic.LivelloMagia.INTERMEDIO, Color.green, 2, 100));
		m.getAzioni().add(ActionCreator.createMagic("Wind 3", Magic.LivelloMagia.AVANZATO, Color.green, 10, 120));
		
		return c;
	}

	public static Classe createClasseHealer(SuperGDR9000 gdr){
		Classe c = new Classe();
		c.setName("Healer");
		c.setSprite(createSprite(gdr, 4*80));
		
		Azione a = ActionCreator.createMove();
		c.getAzioni().add(a);
		
		a = ActionCreator.createAttack();
		c.getAzioni().add(a);
		
		ActionMenu m = ActionCreator.createActionMenu("Magic");
		c.getAzioni().add(m);
		
		m.getAzioni().add(ActionCreator.createHealMagic("Heal 1", Magic.LivelloMagia.BASE, Color.white, 0, 80));
		m.getAzioni().add(ActionCreator.createHealMagic("Heal 2", Magic.LivelloMagia.INTERMEDIO, Color.white, 3, 100));
		m.getAzioni().add(ActionCreator.createHealMagic("Heal 3", Magic.LivelloMagia.AVANZATO, Color.white, 10, 120));
		
		return c;
	}


	protected static AnimatedSprite createSprite(SuperGDR9000 gdr, int startFrom){
		BufferedImage[] b = gdr.bsLoader.getImages("data/pokemon-small.png", 24, 26);
		BufferedImage[] bb = new BufferedImage[4];
		for (int i=0; i<bb.length; i++)
			bb[i] = b[startFrom+i];
		AnimatedSprite as = new AnimatedSprite(bb);
		bb = null;
		b = null;
		as.setAnimationTimer(new Timer(200));
	    as.setAnimate(true);
	    as.setLoopAnim(true);
	    as.setAnimationFrame(0, 3);
		return as;
	}
}
